Repository navigation
Conversation
maleadt
force-pushed
the
tb/unique
branch
3 times, most recently
from
November 5, 2026 13:55
4e9977a to
d3126b3
Compare
A comparator can capture an array, for example to sort the columns of a matrix by their contents. Since Adapt 4.8, such arrays are converted when a kernel captures the ordering, so require that version.
These indexed the array element by element. Instead, sort the elements so that equal ones are adjacent, mark the first of each group at its original position, and select the marked elements. This returns them in the order Base does. `unique(A; dims)` sorts the slice indices with a comparator that compares slices. Elements are ordered with `isless`, or with `isless` on the real and imaginary parts for complex numbers. Element types without `isless` throw an error. x-ref JuliaGPU/CUDA.jl#991
`union`, `intersect`, `setdiff`, `symdiff`, `issubset`, `issetequal` and `isdisjoint` indexed the arrays element by element. Build them on `unique`, and check membership with a binary search in the sorted other array. Elements of different types are compared without converting them, as `isequal` does. Element types, order and errors match Base, including the change to `setdiff`'s element type in Julia 1.13. Membership uses `isequal`, like Base's sets; Base's `issubset` and `isdisjoint` use `==` for arrays of fewer than 70 elements. x-ref #674
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
unique,unique!,allunique,union,intersect,setdiff,symdiff,issubset,issetequalandisdisjointfell back to Base, which indexes GPU arrays element by element (JuliaGPU/CUDA.jl#991). This implements them for all back-ends using the existingsortperm,sortand logical indexing.uniquesorts the elements so that equal ones are adjacent, marks the first of each group at its original position, and selects the marked elements. This returns them in the same order as Base.unique(A; dims)sorts the slice indices with a comparator that reads the array, which needs Adapt 4.8 (JuliaGPU/Adapt.jl#130). JLArrays' host sort now converts such captured arrays too.The set operations use
unique, and check membership with a binary search in the sorted other array. Elements of different types are compared without converting them. Element types, order and errors match Base on Julia 1.10 to 1.13. Elements are ordered withisless, which complex numbers don't have, so those are ordered by their real and imaginary parts. Membership usesisequal, like Base's sets. Base'sissubsetandisdisjointuse==for arrays of fewer than 70 elements, which only makes a difference for NaN, ±0.0 andmissing.Not included: arguments mixing GPU and CPU arrays,
union!and the other mutating functions, andallequal.The first commit renames JLArrays'
_hostand_host_sourcehelpers.Timings on an RTX 5080, for Int64 elements (median of 10 runs; CPU is a single run of Base):
unique, 10⁸ elements, 10⁶ distinctunique(A; dims=2), 8×10⁶unique(A; dims=2), 512×10⁴intersect/setdiff, 10⁷ eachunion/symdiff, 10⁷ eachFixes #674